﻿using Comissoes.Security;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Text;

namespace Comissoes.Controllers
{
    public class AppController : Controller
    {
        public AppController()
        {
        }

        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (!Access.IsLogged)
            {
                if (filterContext.HttpContext.Request.IsAjaxRequest())
                {
                    filterContext.Result = JavaScript("window.top.location.href ='" + Url.Action("Login", "Acesso") + "';");
                }
                else
                {
                    filterContext.Result = RedirectToRoute("Login");
                }
            }
            else
            {
                StringBuilder scripts = new StringBuilder();

                scripts.AppendLine("<title>Index</title>");
                scripts.AppendLine("<!-- CSS -->");
                scripts.AppendLine("<link rel=\"stylesheet\" type=\"text/css\" href=\"../../Content/cssIframe.css\" />");
                scripts.AppendLine("<!-- JS Default -->");
                scripts.AppendLine("<script type=\"text/javascript\" src=\"../../Scripts/jquery-1.4.2.min.js\"></script>");
                scripts.AppendLine("<script type=\"text/javascript\" src=\"../../Scripts/Default.js\"></script>");
                scripts.AppendLine("<script type=\"text/javascript\" src=\"../../Scripts/Extension.js\"></script>");
                scripts.AppendLine("<!-- JS Plugins -->");
                scripts.AppendLine("<script type=\"text/javascript\" src=\"../../Scripts/plugins/jquery-ui-1.8.6/js/jquery-ui-1.8.6.custom.min.js\"></script>");
                scripts.AppendLine("<script type=\"text/javascript\" src=\"../../Scripts/Plugins/jquery-jqGrid-3.8/js/i18n/grid.locale-pt-br.js\"></script>");
                scripts.AppendLine("<script type=\"text/javascript\" src=\"../../Scripts/plugins/jquery-jqGrid-3.8/js/jquery.jqGrid.min.js\"></script>");
                scripts.AppendLine("<script type=\"text/javascript\" src=\"../../Scripts/plugins/jquery-formatcurrency/jquery.formatCurrency-1.4.0.min.js\"></script>");
                scripts.AppendLine("<script type=\"text/javascript\" src=\"../../Scripts/plugins/jquery-formatcurrency/i18n/jquery.formatCurrency.pt-BR.js\"></script>");
                scripts.AppendLine("<script type=\"text/javascript\" src=\"../../Scripts/plugins/jquery-meiomask-1.1.3/jquery-meiomask-1.1.3.min.js\"></script>");
                scripts.AppendLine("<script type=\"text/javascript\" src=\"../../Scripts/plugins/jquery-fiscal/ie.js\"></script>");

                ViewData["scripts"] = scripts.ToString();

                base.OnActionExecuting(filterContext);
            }
        }
    }
}
